<?php

namespace app\store\model;
use app\common\model\Material as MaterialModel;
class Material extends MaterialModel
{
    /**
     * 获取材料列表
     * @param $tasks_id
     * @return array|void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function list($tasks_id){
        $data = self::where(['tasks_id'=>$tasks_id])->select();
        if(!empty($data)){
            return $data->toArray();
        }
        return $data;
    }

    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($data,$tasks_id){
        self::destroy(['tasks_id'=>$tasks_id]);
        $result = false;
        foreach ($data as  $item){
            $_model = clone $this;
            $item['tasks_id']= $tasks_id;
            $result = $_model->allowField(true)->save($item);
        }
        return $result;
    }

}